<template>
  <a-card>
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-tabs default-active-key="1" force-render>
          <a-tab-pane key="1" tab="支付配置">
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="支付方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="PayType">
<!--                  <j-dict-select-tag v-model="queryParam.PayType" placeholder="请选择支付方式" dictCode="pay_type"/>-->
                  <j-multi-select-tag
                    v-model="model.PayType"
                    type="checkbox"
                    dictCode="pay_type"
                    @getArray="getArray"
                    placeholder="请选择支付方式">
                  </j-multi-select-tag>
<!--                  <a-input v-model="model.WxMchId" placeholder="请输入微信商户ID"></a-input>-->
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane key="2" tab="微信支付1参数">
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="微信商户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxMchId">
                  <a-input v-model="model.WxMchId" placeholder="请输入微信商户ID"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信程序ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxAppId">
                  <a-input v-model="model.WxAppId" placeholder="请输入微信程序ID"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信V3API KEY" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxV3ApiKey">
                  <a-input v-model="model.WxV3ApiKey" placeholder="请输入微信V3API KEY"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信V3商户API私钥路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxV3PrivateKeyPath">
                  <a-input v-model="model.WxV3PrivateKeyPath" placeholder="请输入微信V3商户API私钥路径"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信V3商户证书序列号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxV3MerchantSerialNumber">
                  <a-input v-model="model.WxV3MerchantSerialNumber" placeholder="请输入微信V3商户证书序列号"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信支付回调" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxNotifyUrl">
                  <a-input v-model="model.WxNotifyUrl" placeholder="请输入微信支付回调"  ></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane key="3" tab="微信支付2参数">
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="微信商户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxMchId2">
                  <a-input v-model="model.WxMchId2" placeholder="请输入微信商户ID"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信程序ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxAppId2">
                  <a-input v-model="model.WxAppId2" placeholder="请输入微信程序ID"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信V3API KEY" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxV3ApiKey2">
                  <a-input v-model="model.WxV3ApiKey2" placeholder="请输入微信V3API KEY"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信V3商户API私钥路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxV3PrivateKeyPath2">
                  <a-input v-model="model.WxV3PrivateKeyPath2" placeholder="请输入微信V3商户API私钥路径"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信V3商户证书序列号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxV3MerchantSerialNumber2">
                  <a-input v-model="model.WxV3MerchantSerialNumber2" placeholder="请输入微信V3商户证书序列号"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="微信支付回调" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxNotifyUrl2">
                  <a-input v-model="model.WxNotifyUrl2" placeholder="请输入微信支付回调"  ></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane key="4" tab="支付宝支付参数" force-render>
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="支付宝合作者ID(PID)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiPid">
                  <a-input v-model="model.ALiPid" placeholder="请输入支付宝合作者ID"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="支付宝应用ID(AppId)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiAppId">
                  <a-input v-model="model.ALiAppId" placeholder="请输入支付宝应用ID"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="支付宝公钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiKeyPublic">
                  <a-input v-model="model.ALiKeyPublic" placeholder="请输入支付宝公钥"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="支付宝应用私钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiKeyPrivate">
                  <a-input v-model="model.ALiKeyPrivate" placeholder="请输入支付宝应用私钥"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="支付宝支付回调" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiNotifyUrl">
                  <a-input v-model="model.ALiNotifyUrl" placeholder="请输入支付宝支付回调"  ></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane key="5" tab="银行卡支付参数" force-render>
          </a-tab-pane>
          <a-tab-pane key="6" tab="融云音视频IM参数" force-render>
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="融云 数据中心" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="RyServerApi">
                  <a-input v-model="model.RyServerApi" placeholder="请输入融云 数据中心"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="融云 APPKey" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="RyAppKey">
                  <a-input v-model="model.RyAppKey" placeholder="请输入融云 APPKey"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="融云 AppSecret" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="RyAppSecret">
                  <a-input v-model="model.RyAppSecret" placeholder="请输入融云 AppSecret"  ></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-tab-pane>
<!--          <a-tab-pane key="7" tab="相芯科技美颜参数" force-render>
            Content of Tab Pane 3
          </a-tab-pane>
          <a-tab-pane key="8" tab="短信参数" force-render>
            Content of Tab Pane 3
          </a-tab-pane>-->
          <a-tab-pane key="9" tab="微信登录参数" force-render>
            <a-col :span="24">
              <a-form-model-item label="微信登录APPID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxLoginAppId">
                <a-input v-model="model.WxLoginAppId" placeholder="请输入微信登录APPID"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="微信登录Secret" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WxLoginSecret">
                <a-input v-model="model.WxLoginSecret" placeholder="请输入微信登录Secret"  ></a-input>
              </a-form-model-item>
            </a-col>
          </a-tab-pane>
          <a-tab-pane key="10" tab="阿里认证相关参数" force-render>
            <a-col :span="24">
              <a-form-model-item label="accessKey" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiAccessKey" help="注意：阿里OSS、二要素认证、活体认证、人脸比对1:1都用这个参数">
                <a-input v-model="model.ALiAccessKey" placeholder="请输入阿里AccessKey"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="secretKey" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiSecretKey" help="注意：阿里OSS、二要素认证、活体认证、人脸比对1:1都用这个参数">
                <a-input v-model="model.ALiSecretKey" placeholder="请输入阿里SecretKey"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="OSS Endpoint" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiOssEndpoint">
                <a-input v-model="model.ALiOssEndpoint" placeholder="请输入阿里OSS Endpoint"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="OSS BucketName" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ALiOssBucketName">
                <a-input v-model="model.ALiOssBucketName" placeholder="请输入阿里OSS BucketName"  ></a-input>
              </a-form-model-item>
            </a-col>
          </a-tab-pane>
          <a-tab-pane key="11" tab="数美数据审核相关参数" force-render>
            <a-col :span="24">
              <a-form-model-item label="appId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="SMAppId">
                <a-input v-model="model.SMAppId" placeholder="请输入数美Appid"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="accessKey" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="SMAccessKey">
                <a-input v-model="model.SMAccessKey" placeholder="请输入数美AccessKey"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="视频审核回调地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="SMVideoCallback">
                <a-input v-model="model.SMVideoCallback" placeholder="请输入数美视频审核回调地址"  ></a-input>
              </a-form-model-item>
            </a-col>
          </a-tab-pane>
        </a-tabs>

        <a-row>
          <a-col :span="24">
            <a-form-model-item v-bind="formItemLayoutWithOutLabel">
              <a-button type="primary" style="width: 150px;" @click="submitForm">保存</a-button>
            </a-form-model-item>
          </a-col>
        </a-row>

      </a-form-model>
    </a-spin>
  </a-card>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'SystemConfig',
  components: {},
  data () {
    return {
      model:{
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 10 },
      },
      formItemLayoutWithOutLabel: {
        wrapperCol: {
          xs: { span: 24, offset: 0 },
          sm: { span: 20, offset: 5 },
        },
      },
      confirmLoading: false,
      validatorRules: {
        PayType:[
          { required: true, message: '请选择支付方式!',name:'支付方式'},
        ],

        WxMchId: [
          { required: true, message: '请输入请输入微信商户ID!',name:'微信商户ID'},
        ],
        WxAppId: [
          { required: true, message: '请输入微信程序ID!',name:'微信程序ID'},
        ],
        WxNotifyUrl: [
          { required: true, message: '请输入微信支付回调!',name:'微信支付回调'},
        ],
        WxV3ApiKey: [
          { required: true, message: '请输入微信V3API KEY!',name:'微信V3API KEY'},
        ],
        WxV3PrivateKeyPath: [
          { required: true, message: '请输入微信V3商户API私钥路径!',name:'微信V3商户API私钥路径'},
        ],
        WxV3MerchantSerialNumber: [
          { required: true, message: '请输入微信V3商户证书序列号!',name:'微信V3商户证书序列号'},
        ],

        WxMchId2: [
          { required: false, message: '请输入请输入微信商户ID!',name:'2微信商户ID'},
        ],
        WxAppId2: [
          { required: false, message: '请输入微信程序ID!',name:'2微信程序ID'},
        ],
        WxNotifyUrl2: [
          { required: false, message: '请输入微信支付回调!',name:'2微信支付回调'},
        ],
        WxV3ApiKey2: [
          { required: false, message: '请输入微信V3API KEY!',name:'2微信V3API KEY'},
        ],
        WxV3PrivateKeyPath2: [
          { required: false, message: '请输入微信V3商户API私钥路径!',name:'2微信V3商户API私钥路径'},
        ],
        WxV3MerchantSerialNumber2: [
          { required: false, message: '请输入微信V3商户证书序列号!',name:'2微信V3商户证书序列号'},
        ],


        WxLoginAppId: [
          { required: true, message: '请输入微信登录APPID!',name:'微信登录APPID'},
        ],
        WxLoginSecret: [
          { required: true, message: '请输入微信登录Secret!',name:'微信登录Secret'},
        ],

        ALiPid: [
          { required: true, message: '请输入支付宝合作者ID!',name:'支付宝合作者ID'},
        ],
        ALiAppId: [
          { required: true, message: '请输入支付宝应用ID!',name:'支付宝应用ID'},
        ],
        ALiKeyPublic: [
          { required: true, message: '请输入支付宝公钥!',name:'支付宝公钥'},
        ],
        ALiKeyPrivate: [
          { required: true, message: '请输入支付宝应用私钥!',name:'支付宝应用私'},
        ],
        ALiNotifyUrl: [
          { required: true, message: '请输入支付宝支付回调!',name:'支付宝支付回调'},
        ],


        RyServerApi: [
          { required: true, message: '请输入融云数据中心！',name:'融云数据中心'},
        ],
        RyAppKey: [
          { required: true, message: '请输入阿里SecretKey!',name:'融云APPKey'},
        ],
        RyAppSecret: [
          { required: true, message: '请输入融云AppSecret!',name:'融云AppSecret'},
        ],

        ALiSecretKey: [
          { required: true, message: '请输入阿里SecretKey!',name:'阿里SecretKey'},
        ],
        ALiAccessKey: [
          { required: true, message: '请输入阿里AccessKey!',name:'阿里AccessKey'},
        ],
        ALiOssEndpoint: [
          { required: true, message: '请输入阿里OSS Endpoint!',name:'阿里OSS Endpoint'},
        ],
        ALiOssBucketName: [
          { required: true, message: '请输入阿里OSS BucketName!',name:'阿里OSS BucketName'},
        ],

        SMAppId: [
          { required: true, message: '请输入数美Appid',name:'数美Appid'},
        ],
        SMAccessKey: [
          { required: true, message: '请输入数美AccessKey!',name:'数美AccessKey'},
        ],
        SMVideoCallback: [
          { required: true, message: '请输入数美视频审核回调地址!',name:'数美视频审核回调地址'},
        ],
      },

      payArray:[],
    }
  },
  created() {
    this.getSystemConfigMap();
  },
  methods: {
    //获取回显数据
    getSystemConfigMap(){
      getAction('/system/systemConfig/getSystemConfigMap').then((res)=>{
        if(res.success){
          this.model=res.result;
          var PayType=[];
          if(res.result.PayType){
            let parse = JSON.parse(res.result.PayType);
            this.payArray=parse;
            for (const parseElement of parse) {
              PayType.push(parseElement.code);
            }
            this.model.PayType=PayType.join(",");
          }
        }
      })
    },
    getArray(data){
      this.payArray=data;
    },
    //保存数据
    submitForm () {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '/system/systemConfig/saveOrUpdate';
          let method = 'post';
          let dataList=[];
          //格式化数据
          for(let key in this.model){
            let obj={};
            obj.code=key;
            obj.value=this.model[key];
            if(key=='PayType'){
              obj.value=JSON.stringify(this.payArray);
            }
            if(that.validatorRules[key]){
              obj.title=that.validatorRules[key][0].name;
              dataList.push(obj)
            }


          }

          httpAction(httpurl,dataList,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  },
}
</script>

<style scoped>

</style>